/*
 * @Author: jackning 270580156@qq.com
 * @Date: 2024-05-24 18:25:45
 * @LastEditors: jackning 270580156@qq.com
 * @LastEditTime: 2024-12-27 17:44:14
 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
 *   Please be aware of the BSL license restrictions before installing Bytedesk IM – 
 *  selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. 
 *  仅支持企业内部员工自用，严禁私自用于销售、二次销售或者部署SaaS方式销售 
 *  Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE 
 *  contact: 270580156@qq.com 
 *  技术/商务联系：270580156@qq.com
 * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. 
 */
import React from "react";
import { RichText } from "../RichText";

export interface BubbleProps extends React.HTMLAttributes<HTMLDivElement> {
  type?: string;
  content?: string;
  isRichText?: boolean;
}

export const Bubble = React.forwardRef<HTMLDivElement, BubbleProps>(
  (props, ref) => {
    const { type = "text", content, children, isRichText = false, ...other } = props;

    const renderContent = () => {
      if (!content) return null;
      
      if (isRichText) {
        return <RichText content={content} />;
      }
      
      return <p>{content}</p>;
    };

    return (
      <div className={`Bubble ${type}`} data-type={type} ref={ref} {...other}>
        {renderContent()}
        {children}
      </div>
    );
  },
);
